package GUI.TabPanel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

import Config.GeneralsConfig;
import Logic.TaskMaintain;

public class Advance extends JPanel {

	public void Refresh(Object SelectObject) {
		this.Mac = (String) SelectObject;
		this.intRows2DumpText.setText("" + GeneralsConfig.intRows2Dump);
		this.intSecond4NextTaskText.setText("" + GeneralsConfig.intSecond4NextTask);
		this.intSecond4SQLWaitText.setText(""
				+ GeneralsConfig.intSecond4SQLWait);
		this.intSecond4WaitText.setText("" + GeneralsConfig.intSecond4Wait);
	}

	public Advance() {
		// TODO Auto-generated constructor stub

		this.intRows2Dump = new JLabel("intRows2Dump");
		this.intSecond4NextTask = new JLabel("intSecond4Next");
		this.intSecond4SQLWait = new JLabel("intSecond4SQLWait");
		this.intSecond4Wait = new JLabel("intSecond4Wait");

		this.intRows2DumpText = new JTextField(GeneralsConfig.intRows2Dump);
		this.intSecond4NextTaskText = new JTextField(
				GeneralsConfig.intSecond4NextTask);
		this.intSecond4SQLWaitText = new JTextField(
				GeneralsConfig.intSecond4SQLWait);
		this.intSecond4WaitText = new JTextField(GeneralsConfig.intSecond4Wait);

		this.save = new JButton("save");

		this.save.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				try {
					if (Integer.valueOf(intRows2DumpText.getText()) != GeneralsConfig.intRows2Dump) {
						TaskMaintain.writeVAL(Mac, "intRows2Dump",
								intRows2DumpText.getText());
						GeneralsConfig.intRows2Dump = Integer.valueOf(intRows2DumpText.getText());
					}
					
					if (Integer.valueOf(intSecond4NextTaskText.getText()) != GeneralsConfig.intSecond4NextTask ) {
						TaskMaintain.writeVAL(Mac, "intSecond4NextTask",
								intSecond4NextTaskText.getText());
						GeneralsConfig.intSecond4NextTask = Integer.valueOf(intSecond4NextTaskText.getText());
					}
					
					if (Integer.valueOf(intSecond4SQLWaitText.getText()) != GeneralsConfig.intSecond4SQLWait) {
						TaskMaintain.writeVAL(Mac, "intSecond4SQLWait",
								intSecond4SQLWaitText.getText());
						GeneralsConfig.intSecond4SQLWait = Integer.valueOf(intSecond4SQLWaitText.getText());
					}
					
					if (Integer.valueOf(intSecond4WaitText.getText()) != GeneralsConfig.intSecond4Wait) {
						TaskMaintain.writeVAL(Mac, "intSecond4Wait",
								intSecond4WaitText.getText());
						GeneralsConfig.intSecond4Wait = Integer.valueOf(intSecond4WaitText.getText());
					}
					
					// 解决多生成CON命令
					//TaskMaintain.writeCON(Mac);
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}

		});

		GroupLayout layout = new GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(44, 44, 44)
								.addGroup(
										layout.createParallelGroup(
												GroupLayout.Alignment.LEADING,
												false)
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		intRows2Dump)
																.addPreferredGap(
																		LayoutStyle.ComponentPlacement.RELATED,
																		GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.addComponent(
																		intRows2DumpText,
																		100,
																		100,
																		100))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		intSecond4Wait)
																.addPreferredGap(
																		LayoutStyle.ComponentPlacement.RELATED,
																		GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.addComponent(
																		intSecond4WaitText,
																		100,
																		100,
																		100)))
								.addPreferredGap(
										LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		intSecond4NextTask)
																.addPreferredGap(
																		LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(
																		intSecond4NextTaskText,
																		100,
																		100,
																		100))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		intSecond4SQLWait)
																.addPreferredGap(
																		LayoutStyle.ComponentPlacement.RELATED)
																.addGroup(
																		layout.createParallelGroup(
																				GroupLayout.Alignment.LEADING)
																				.addComponent(
																						save)
																				.addComponent(
																						intSecond4SQLWaitText,
																						100,
																						100,
																						100))))
								.addContainerGap(58, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout.createParallelGroup(
				GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addGap(37, 37, 37)
						.addGroup(
								layout.createParallelGroup(
										GroupLayout.Alignment.BASELINE)
										.addComponent(intSecond4Wait)
										.addComponent(intSecond4NextTask)
										.addComponent(intSecond4WaitText,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE)
										.addComponent(intSecond4NextTaskText,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))
						.addGap(71, 71, 71)
						.addGroup(
								layout.createParallelGroup(
										GroupLayout.Alignment.BASELINE)
										.addComponent(intRows2Dump)
										.addComponent(intSecond4SQLWait)
										.addComponent(intRows2DumpText,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE)
										.addComponent(intSecond4SQLWaitText,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(
								LayoutStyle.ComponentPlacement.RELATED, 75,
								Short.MAX_VALUE).addComponent(save)
						.addGap(33, 33, 33)));
	}

	private JLabel intSecond4Wait;
	private JLabel intSecond4NextTask;
	private JLabel intRows2Dump;
	private JLabel intSecond4SQLWait;
	private JTextField intSecond4WaitText;
	private JTextField intSecond4NextTaskText;
	private JTextField intRows2DumpText;
	private JTextField intSecond4SQLWaitText;
	private String Mac;
	private JButton save;

}
